﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;

namespace Meridian.BindingConverters
{
    public class BeginTimeConverter : IValueConverter
    {
        private int index = -1;
        private bool firstLoad;

        public object Convert(object value, Type targetType, object parameter,
                       CultureInfo culture)
        {
            if (value != null)
            {
                if (index == -1)
                {
                    index = 0;
                    firstLoad = true;
                }

                var result = TimeSpan.FromMilliseconds(50 * index + 70);
                index++;
                if (firstLoad)
                {
                    if (index == App.Settings.FirstLoadItemsCount)
                        index = 0;
                }
                else
                    if (index == App.Settings.DynamicLoadItemsCount)
                        index = 0;

                return result;
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter,
                           CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
